package edu.jmu.transmissionassistant.model

import android.os.Parcel
import android.os.Parcelable
import android.os.Parcelable.Creator
import com.alibaba.fastjson.annotation.JSONField

open class ReturnData() : Parcelable {
    @JSONField(name = "isSuccess")
    var isSuccess = false

    @JSONField(name = "errorCode")
    var errorCode = 0

    @JSONField(name = "errorMsg")
    var errorMsg: String? = null

    @JSONField(name = "data")
    var data: Any? = null

    constructor(parcel: Parcel) : this() {
        isSuccess = parcel.readByte().toInt() != 0
        errorCode = parcel.readInt()
        errorMsg = parcel.readString()
    }

    override fun writeToParcel(dest: Parcel, flags: Int) {
        dest.writeByte((if (isSuccess) 1 else 0).toByte())
        dest.writeInt(errorCode)
        dest.writeString(errorMsg)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object {
        @JvmField
        val CREATOR: Creator<ReturnData?> = object : Creator<ReturnData?> {
            override fun createFromParcel(input: Parcel): ReturnData {
                return ReturnData(input)
            }

            override fun newArray(size: Int): Array<ReturnData?> {
                return arrayOfNulls(size)
            }
        }
    }
}